<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/inc/taglib.jsp"%>
<!-- 引用ztree 的css -->
<link rel="stylesheet" href="${pageContext.request.contextPath}/statics/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<div class="pageHeader">
	<form id="pagerForm" onsubmit="return navTabSearch(this);" action="${pageContext.request.contextPath}/system/permission/list" method="post">
		<!-- 分页表单参数 -->
		<%@include file="/WEB-INF/page/inc/pageForm.jsp"%>
		<div class="searchBar">
			<table class="searchContent">
				<tr>
					<td></td>
				</tr>
			</table>
			<div class="subBar">
				<!-- <ul>
                        <li><div class="buttonActive">
                                        <div class="buttonContent">
                                                <button type="submit">查询</button>
                                        </div>
                                </div></li>
                </ul> -->
			</div>
		</div>
	</form>
</div>
<div class="pageContent j-resizeGrid">
	<!-- 按钮 -->
	<div class="panelBar">
		<ul class="toolBar">
			<!-- 局部刷新 在a标签添加属性  target="ajax" 和添加 rel="所要刷新的位置"-->
				<li><a class="add" mask="true" href="${pageContext.request.contextPath}/system/permission/toInsert" rel="permissionBox"><span>添加</span></a></li>
				<li><a class="edit" mask="true" href="${pageContext.request.contextPath}/system/permission/toUpdate?id=" rel="update"><span>修改</span></a></li>
				<li><a class="delete" mask="true" href="${pageContext.request.contextPath}/system/permission/delete?id="><span>删除</span></a></li>
		</ul>
	</div>
	<!-- 左布局 -->
	<div  style="float: left; display: block; overflow: auto; width: 240px; border: solid 1px #CCC; background: #fff">
		<!-- <ul class="tree treeFolder"> -->
		<ul  layoutH="100"id="permissionTree" class="ztree"></ul>
	</div>
	<!-- 右布局 -->
	<div id="permissionBox" class="unitBox" style="margin-left: 246px;"></div>
</div>

<!-- ztree js -->
<script type="text/javascript" src="${pageContext.request.contextPath}/statics/ztree/js/jquery.ztree.core.js">
	
</script>
<script type="text/javascript">
	var setting = {
		data : {
			simpleData : {
				enable : true
			}
		},
		view : {
			selectedMulti : false
		//不允许多选
		},
		callback : {
			onClick : onClick1
		}
	};
	var selected = null;
	var selectedLevel = null;

	/* eventjs event 对象
	标准的 js event 对象
	treeIdString
	对应 zTree 的 treeId，便于用户操控
	treeNodeJSON
	被点击的节点 JSON 数据对象
	clickFlagNumber */
	function onClick1(event, treeId, treeNode, clickFlag) {
		var treeObj = $.fn.zTree.getZTreeObj(treeId, navTab.getCurrentPanel());
		var nodes = treeObj.getSelectedNodes();
		if (nodes[0].id == selected) {
			//两次点击取消
			treeObj.cancelSelectedNode();
			selected = null;
			selectedLevel = null;
		} else {
			selected = treeNode.id;
			selectedLevel = (treeNode.level + 1);
		}

	}

	var zNodes = ${requestScope.ztreeBeans};
	$(document, navTab.getCurrentPanel()).ready(function() {
		//ztree初始化  ztree 设置参数   ztree 内容
		$.fn.zTree.init($("#permissionTree", navTab.getCurrentPanel()), setting, zNodes);
	});
	//添加
	$(".add", navTab.getCurrentPanel()).click(function() {
		/* if (selectedLevel >= 3) {
		    alertMsg.error('等级超过上限！');
		    // 取消选中
		    var treeObj = $.fn.zTree.getZTreeObj("permissionTree", navTab.getCurrentPanel());
		    treeObj.cancelSelectedNode();
		    $("#permissionBox", navTab.getCurrentPanel()).empty();
		    return false;
		} */
		if (selected) {
			//子菜单
			$("#permissionBox", navTab.getCurrentPanel()).loadUrl($(this).attr("href") + "?pid=" + selected, null, null);
		} else {
			//父级菜单
			$("#permissionBox", navTab.getCurrentPanel()).loadUrl($(this).attr("href"), null, null);
		}
		return false;
	});
	//修改
	$(".edit", navTab.getCurrentPanel()).click(function() {
		if (selected) {
			//不为空
			$("#permissionBox", navTab.getCurrentPanel()).loadUrl($(this).attr("href") + selected, null, null);
		} else {
			//空
			alertMsg.error('请选择一个记录')
		}
		//跳连接功能拦截
		return false;
	});
	//删除
	$(".delete", navTab.getCurrentPanel()).click(function() {
		if (selected) {
			//不为空
			alertMsg.confirm("确定要删除吗？", {
				okCall : function() {
					ajaxTodo($(".delete", navTab.getCurrentPanel()).attr("href") + selected);
				}
			});
		} else {
			//空
			alertMsg.error('请选择一个记录')
		}
		//跳连接功能拦截
		return false;
	});
</script>